/**
 * @file pt_bat_param_info_converter.c
 * @version 1.0
 * @date August 2024 
 * @author WSH
 *
 * @brief
 *  系统参数配置.
 * @note
 * @details
 
 *    if(pac_pkg->PacketSender.type == PTL_BAT_PARAM_INFO_DATA_ID){
 *        pt_decode_bat_param_info(&pac_pkg->buffer[8],pac_pkg->buffer[7],&rec_bat_param_info);
 *    }
 *
 * @Copyright (c) 2024 WSH
 */
// pt_bat_param_info.c
#include "pt_battery_control_converter.h"

// bat_param_info_t rec_bat_param_info;

int pt_pack_bat_param_info(bat_param_info_t bat_param_info,PacketSender_t PacketSender,uint8_t *data,uint16_t max_len){
    int index,ret_len;
    index = ptl_encode_head(&PacketSender,data,PTL_BAT_PARAM_INFO_DATA_ID,PTL_BAT_PARAM_INFO_DATA_SIZE,max_len);
    data[index] = bat_param_info.battery_temp_source;index ++ ;
    index = ptl_pack_int16(data,bat_param_info.day_upper_temp_limit, index);
    index = ptl_pack_int16(data,bat_param_info.day_lower_temp_limit, index);
    index = ptl_pack_int16(data,bat_param_info.night_upper_temp_limit, index);
    index = ptl_pack_int16(data,bat_param_info.night_lower_temp_limit, index);
    index = ptl_pack_uint32(data,bat_param_info.upper_battery_volt, index);
    index = ptl_pack_uint32(data,bat_param_info.lower_battery_volt, index);
    index = ptl_pack_int32(data,bat_param_info.upper_battery_curr, index);
    index = ptl_pack_int32(data,bat_param_info.charge_upper_curr, index);
    index = ptl_pack_uint16(data,bat_param_info.comm_timeout_time, index);
    index = ptl_pack_uint16(data,bat_param_info.precharge_contact_time, index);
    index = ptl_pack_uint16(data,bat_param_info.main_contact_time, index);
    index = ptl_pack_float32(data,bat_param_info.volt_coefficient, index);
    index = ptl_pack_uint16(data,bat_param_info.curr_ref_volt, index);
    index = ptl_pack_float32(data,bat_param_info.volt_offset, index);
    index = ptl_pack_float32(data,bat_param_info.curr_calib_coeff, index);
    index = ptl_pack_float32(data,bat_param_info.curr_calib_offset, index);
    index = ptl_pack_float32(data,bat_param_info.int_resistance, index);
    ret_len = ptl_encode_tail(data,index,max_len);
    return ret_len;
}
int pt_decode_bat_param_info(uint8_t *datain,uint16_t data_len,bat_param_info_t *pt_bat_param_info){
    int index = 0;
    pt_bat_param_info->battery_temp_source = datain[index] ;index ++ ;
    pt_bat_param_info->day_upper_temp_limit = ptl_depack_int16(datain,&index) ;
    pt_bat_param_info->day_lower_temp_limit = ptl_depack_int16(datain,&index) ;
    pt_bat_param_info->night_upper_temp_limit = ptl_depack_int16(datain,&index) ;
    pt_bat_param_info->night_lower_temp_limit = ptl_depack_int16(datain,&index) ;
    pt_bat_param_info->upper_battery_volt = ptl_depack_uint32(datain,&index) ;
    pt_bat_param_info->lower_battery_volt = ptl_depack_uint32(datain,&index) ;
    pt_bat_param_info->upper_battery_curr = ptl_depack_int32(datain,&index) ;
    pt_bat_param_info->charge_upper_curr = ptl_depack_int32(datain,&index) ;
    pt_bat_param_info->comm_timeout_time = ptl_depack_uint16(datain,&index) ;
    pt_bat_param_info->precharge_contact_time = ptl_depack_uint16(datain,&index) ;
    pt_bat_param_info->main_contact_time = ptl_depack_uint16(datain,&index) ;
    pt_bat_param_info->volt_coefficient = ptl_depack_float32(datain,&index) ;
    pt_bat_param_info->curr_ref_volt = ptl_depack_uint16(datain,&index) ;
    pt_bat_param_info->volt_offset = ptl_depack_float32(datain,&index) ;
    pt_bat_param_info->curr_calib_coeff = ptl_depack_float32(datain,&index) ;
    pt_bat_param_info->curr_calib_offset = ptl_depack_float32(datain,&index) ;
    pt_bat_param_info->int_resistance = ptl_depack_float32(datain,&index) ;
    return 0;
}
